package game_logic.util;

import game_logic.view.SimpleBoardView;

public interface Utils {
    /**
     * 传入横纵坐标
     *
     * @param modelPos
     * @return
     */
    static int[] getViewPos(int modelPos[], boolean reverseBoard) {
        if (reverseBoard) {
            modelPos[0] = 8 - modelPos[0];
            modelPos[1] = 9 - modelPos[1];
        }
        int sx = modelPos[0] * SimpleBoardView.UNIT_SIZE + SimpleBoardView.START_OFFSET_X, sy = modelPos[1] * SimpleBoardView.UNIT_SIZE + SimpleBoardView.START_OFFSET_Y;
        return new int[]{sx, sy};
    }

    static int[] getModelPos(int viewPos[], boolean reverseBoard) {
        /* To make things right, I have to put an 'additional sy offset'. God knows why. */
        int ADDITIONAL_SY_OFFSET = 25;
        int x = (viewPos[0] - SimpleBoardView.START_OFFSET_X) / SimpleBoardView.UNIT_SIZE;
        int y = (viewPos[1] - SimpleBoardView.START_OFFSET_Y - ADDITIONAL_SY_OFFSET) / SimpleBoardView.UNIT_SIZE;
        if (reverseBoard) {
            x = 8 - x;
            y = 9 - y;
        }
        return new int[]{x, y};
    }
}
